#ifndef X3__H
#define X3__H

#include "common.h"


// `x30` wraps a string graphic object and includes info like rotation and
// layer.
enum TextAlignment : uint8_t
{
    TextAlignLeft = 1,
    TextAlignRight,
    TextAlignCenter
};

enum TextReversal : uint8_t
{
    TextStraight = 0,
    TextReversed = 1
};

struct TextProperties
{
    uint8_t key;
    uint8_t bm1;
    TextAlignment align;
    TextReversal reversed;
};
template <AllegroVersion version>
struct x30
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;
    uint32_t k;
    uint32_t next;
    
    // Pointer to string graphic object
    uint32_t str_graphic_ptr;
    uint32_t un1;
    TextProperties font_16x;
    
    int32_t coords[2];
    uint32_t un3;
    
    uint32_t rotation;
    uint32_t ptr3_16x;
    
    uint32_t TAIL;
    operator x30<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};

#if __cplusplus >= 202002L
template <AllegroVersion version> requires(version >= A_172)
struct x30<version>
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;
    uint32_t k;
    uint32_t next;

    uint32_t un4;
    uint32_t un5;
    TextProperties font;
    uint32_t ptr3;
    uint32_t un7;

    // Pointer to string graphic object
    uint32_t str_graphic_ptr;
    uint32_t un1;

    uint32_t un6;

    int32_t coords[2];
    uint32_t un3;

    uint32_t rotation;

    uint32_t TAIL;
    operator x30<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};
#else
template <> struct x30<A_172>
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;
    uint32_t k;
    uint32_t next;

    uint32_t un4;
    uint32_t un5;
    TextProperties font;
    uint32_t ptr3;
    uint32_t un7;

    // Pointer to string graphic object
    uint32_t str_graphic_ptr;
    uint32_t un1;

    uint32_t un6;

    int32_t coords[2];
    uint32_t un3;

    uint32_t rotation;

    uint32_t TAIL;
    operator x30<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_172, A_174};
};
template <> struct x30<A_174> : x30<A_172> {};
#endif

#endif // X3__H
